package com.fufan.mtsaas.modules.newtech.xjstech.controller;


import com.alibaba.fastjson.JSONObject;
import com.fufan.mtsaas.modules.common.bo.request.DataRequest;
import com.fufan.mtsaas.modules.common.bo.request.DataRequestT;
import com.fufan.mtsaas.modules.common.bo.request.ResultPack;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.modules.newtech.xjstech.bo.request.*;
import com.fufan.mtsaas.modules.newtech.xjstech.bo.response.XjsDeptInfoResponse;
import com.fufan.mtsaas.modules.newtech.xjstech.bo.response.XjsTechResponse;
import com.fufan.mtsaas.modules.newtech.xjstech.bo.response.XjsTechTotal;
import com.fufan.mtsaas.modules.newtech.xjstech.bo.response.XjsThisUserInfo;
import com.fufan.mtsaas.modules.newtech.xjstech.model.XjsTech;
import com.fufan.mtsaas.modules.newtech.xjstech.service.XjsTechSvc;
import com.fufan.mtsaas.util.JSonUtil;
import com.fufan.mtsaas.util.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 新技术-项目申报模块相关接口
 * </p>
 *
 * @author Liby
 * @since 2024-12-16
 */
@Api(tags = "新技术-项目申报模块相关接口", description = "XjsTech对象接口")
@RestController
@RequestMapping("/MTSaas/xjsTech")
@Slf4j
public class XjsTechCtrl {

    @Autowired
    private XjsTechSvc targetService;

    /**
     * 当前用户信息
     */
    @ApiOperation(value = "当前用户信息", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doThisUserInfo")
    public Result<XjsThisUserInfo> doThisUserInfo() {
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doThisUserInfo(requestPojo);
    }

    /**
     * 通过科室ID查询科室信息
     */
    @ApiOperation(value = "通过科室ID查询科室信息", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doDeptInfo")
    public Result<XjsDeptInfoResponse> doDeptInfo(@RequestBody DataRequestT<XjsTechIdRequest> dataRequest) {
        XjsTechIdRequest mapData = dataRequest.getData().getParam();
        return targetService.doDeptInfo(mapData);
    }


    /**
     * 我的申报
     */
    @ApiOperation(value = "我的申报", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doMyTechQuery")
    public Result<XjsTechResponse> doMyTechQuery(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doQueryPage(mapData, requestPojo);
    }

    /**
     * 新增、编辑、暂存申报
     */
    @ApiOperation(value = "新增、编辑、暂存申报", httpMethod = "POST", produces = "application/json",response = Result.class)
    @RequestMapping(value = "/doSave", method = RequestMethod.POST)
    public Result<XjsTech> doSaveMap(@RequestBody @Valid DataRequestT<XjsTechSaveRequest> dataRequest) {
        log.debug("doSave parameter: {}", dataRequest);

        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doSave(dataRequest.getData().getParam(), requestPojo);
    }

    /**
     * 提交申报
     */
    @ApiOperation(value = "提交申报，先调用doSave方法", httpMethod = "PUT", produces = "application/json")
    @RequestMapping(value = "/doUpdate", method = RequestMethod.PUT)
    public Result<XjsTech> doUpdateMap(@RequestBody @ApiIgnore @Valid DataRequestT<XjsTechSaveRequest> dataRequest) {
        log.debug("doUpdate parameter: {}", dataRequest);

        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsTechSaveRequest mapData = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doUpdate(mapData, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 删除数据
     */
    @ApiOperation(value = "删除数据", httpMethod = "DELETE", produces = "application/json")
    @RequestMapping(value = "/doDelete", method = RequestMethod.DELETE)
    public Result doDelete(@RequestBody @ApiIgnore DataRequest dataRequest) {
        log.debug("doDelete parameter: {}", dataRequest);

        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapData = dataRequest.getData().getParam();
        XjsTechDeleteRequest map = JSonUtil.toBean(mapData.toJSONString(), XjsTechDeleteRequest.class);

        return resultPack.doResultPack(targetService.doDelete(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 表单数据、详情
     */
    @ApiOperation(value = "表单数据、详情", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value = "/doDetail", method = RequestMethod.POST)
    public Result<XjsTechResponse> doDetail(@RequestBody @ApiIgnore @Valid DataRequestT<XjsTechQueryByIdRequest> dataRequest) {
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsTechQueryByIdRequest map = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doDetail(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 我的草稿
     */
    @ApiOperation(value = "我的草稿", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doMyDraftQuery")
    public Result<XjsTechResponse> doMyDraftQuery(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doMyDraftQuery(mapData, requestPojo);
    }

    /**
     * 已开通项目
     */
    @ApiOperation(value = "已开通项目", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doOpenedProjectQuery")
    public Result<XjsTechResponse> doOpenedProjectQuery(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doOpenedProjectQuery(mapData, requestPojo);
    }

    /**
     * 导出已开通项目
     */
    @ApiOperation(value = "导出已开通项目", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doExportOpenedProject")
    public Result<XjsTechResponse> doExportOpenedProject(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest, HttpServletResponse response) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doExportOpenedProject(mapData, requestPojo, response);
    }

    /**
     * 待我审批的
     */
    @ApiOperation(value = "待我审批的", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doPendingApprovalQuery")
    public Result<XjsTechResponse> doPendingApprovalQuery(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doPendingApprovalQuery(mapData, requestPojo);
    }

    /**
     * 我已审批的
     */
    @ApiOperation(value = "我已审批的", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doAlreadyApprovedQuery")
    public Result<XjsTechResponse> doAlreadyApprovedQuery(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doAlreadyApprovedQuery(mapData, requestPojo);
    }


    /**
     * 审批
     */
    @ApiOperation(value = "审批", httpMethod = "PUT", produces = "application/json")
    @RequestMapping(value = "/doApprove", method = RequestMethod.PUT)
    public Result<Boolean> doApprove(@RequestBody DataRequestT<XjsTechApproveRequest> dataRequest) {
        log.debug("doApprove parameter: {}", dataRequest);

        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsTechApproveRequest map = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doApprove(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 发短信给申请人
     */
    @ApiOperation(value = "发短信给申请人", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value = "/doSendSms", method = RequestMethod.POST)
    public Result<Boolean> doSendSms(@RequestBody DataRequestT<XjsTechSendSmaRequest> dataRequest) {
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsTechSendSmaRequest map = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doSendSms(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 查询分析--新技术查询列表
     */
    @ApiOperation(value = "查询分析--新技术查询列表", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/selectAllByPage")
    public Result<XjsTechResponse> selectAllByPage(@RequestBody DataRequestT<XjsTechQueryRequest> dataRequest) {
        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.selectAllByPage(mapData, requestPojo);
    }

    /**
     * 查询分析--新技术查询列表数据汇总接口
     */
    @ApiOperation(value = "查询分析--新技术查询列表数据汇总接口", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/selectAllByTotal")
    public Result<XjsTechTotal> selectAllByTotal() {
//        XjsTechQueryRequest mapData = dataRequest.getData().getParam();
//        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.selectAllByTotal();
    }
    @ApiOperation(value = "统计项目条数", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/selectProjectNumber")
    public Result selectProjectNumber() {
        ResultPack resultPack = new ResultPack();

        RequestPojo requestPojo = ParamUtil.doChange();

        return resultPack.doResultPack(targetService.selectProjectNumber(), requestPojo.getIntfId(), requestPojo.getAppKey());

    }
}
